// run: $exec < bfdiff.in
#include <iostream>
#include <algorithm>

int const maxn = 3000007;
long long a[maxn];
int q1[maxn], q2[maxn]; // q1 for increase, q2 for decrease
long long k;
int n;

template <class T>
T abs(T a) { return a < 0 ? -a : a; }

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> k >> n;
	for (int i = 0; i < n; i++) std::cin >> a[i];
	int h1 = 1, t1 = 0, h2 = 1, t2 = 0, left = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		while (h1 <= t1 && a[i] <= a[q1[t1]]) t1--;
		while (h2 <= t2 && a[i] >= a[q2[t2]]) t2--;
		q1[++t1] = i;
		q2[++t2] = i;
		while (abs(a[q1[h1]] - a[q2[h2]]) > k) {
			if (q1[h1] < q2[h2])
				left = std::max(left, q1[h1++] + 1);
			else
				left = std::max(left, q2[h2++] + 1);
		}
		ans = std::max(ans, i - left + 1);
	}
	std::cout << ans << '\n';
}

